//
//  FSCClassRoomListViewModel.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/29.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit
import SVProgressHUD

class FSCClassRoomListViewModel {

    var classRoomModelArr:[FSCClassRoomModel] = []
    
    
    func loadData(finished:@escaping (_ isOk:Bool)->()) -> Void {
        
        let urlStr = "ZH-schoolname-S-getNewMessage"
        let parm = ["key":userID,"id":"4"]
        SVProgressHUD.show()
        FSCNetworkTools.shared.request(url: urlStr, parameters: parm) { [weak self] (data, error) in
            guard let data = data as? NSDictionary  else {
                SVProgressHUD.showInfo(withStatus: "请求失败")
                return
            }
            SVProgressHUD.dismiss()
            print(data,"-----")
            
            switch data["result"] as! Int {
            case 0:
                guard let dictArr = data["data"] as? [NSDictionary] else {
                    return
                }
                for dict in dictArr {
                    let model = FSCClassRoomModel(dict:dict)
                    self?.classRoomModelArr.append(model)
                }
                finished(true)
            case 1:
                SVProgressHUD.showInfo(withStatus: "加载失败")
                finished(false)
            default:
                break
            }
            
        }
    }

}
